#include <iostream>
using std::cout;
using std::endl;


//值传递,利用实参a,b初始化形参x,y
//在函数中改编x,y的值相当于是改变a,b的副本
//不会影响a,b本体
void swap(int x,int y){
    int temp = x;
    x = y;
    y = temp;
}

//地址传递，在函数中对传入的地址上的值进行修改
//修改有效
void swap2(int * px,int * py){
    int temp = *px;
    *px = *py;
    *py = temp;
}

//引用传递,不会发生复制，相当于是指向
//传入实参初始化形参
//相当于int & x = a;  int & y = b;
//在函数体中对引用进行操作就是对实参本身进行操作
void swap3(int & x, int & y){
    int temp = x;
    x = y;
    y = temp;
}

void func(const int & ref){
    /* ref = 100; */
    cout << "ref:" << ref << endl;
}

void test0(){
    int a = 1, b = 2;
    swap2(&a,&b);
    swap3(a,b);
    cout << "a = " << a << endl;
    cout << "b = " << b << endl;

    func(a);
    cout << a << endl;
}

int main(void){
    test0();
    return 0;
}
